﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.models.world.vos.actors.machines {
    import flash.events.*;
    import flash.geom.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;

    public class FountainMachineVO extends AbstractMachineVO {

        public function FountainMachineVO(_arg1:Object, _arg2:IEventDispatcher){
            super(_arg1, _arg2);
            speechBubblePosition = new Point(0, -190);
            this.checkState();
        }
        override public function checkState():void{
        }
        override public function handlePatient(_arg1:ITreatable):void{
            if (_arg1.state == WorldConstants.CURED){
                _arg1.moveToNextTreatment();
            } else {
                _patient = _arg1;
                this.putPatientIntoMachine(true);
                if (((!(_patient.currentTreatment)) || (_patient.currentTreatment.startedAt))){
                    this.state = WorldConstants.FINISHED;
                } else {
                    this.state = WorldConstants.WAITING;
                    dispatch(new InfoEvent(EventConstants.CHECK_FOUNTAIN_TUTORIAL, null, {patient:_patient}));
                };
            };
        }
        override public function set state(_arg1:String):void{
            super.state = _arg1;
            switch (_arg1){
                case WorldConstants.CLEAN:
                    if (_patient){
                        this.putPatientIntoMachine(false);
                        removeSpeechBubble();
                        _patient = null;
                    };
                    break;
                case WorldConstants.WAITING:
                    this.showBubble(SpeechBubbleConstants.ICON_EXCLAMATIONMARK);
                    break;
                case WorldConstants.WORKING:
                    removeSpeechBubble();
                    break;
                case WorldConstants.FINISHED:
                    removeSpeechBubble();
                    this.showBubble(SpeechBubbleConstants.ICON_READY);
                    dispatch(new InfoEvent(EventConstants.FINISH_REGENERATION, null));
                    break;
                default:
                    return;
            };
            dispatch(new InfoEvent(EventConstants.SET_FOUNTAIN_STATE, id, _arg1));
        }
        override public function getAction(_arg1:Object):InfoEvent{
            var _local2:InfoEvent;
            if (!_actionsActive){
                return (null);
            };
            var _local3:Event = new Event(EventConstants.HANDLE_NEXT_AVATAR_ACTION);
            if (state == WorldConstants.WAITING){
                _local2 = this.createSymbolCollectionWindow();
            } else {
                if (state == WorldConstants.FINISHED){
                    _local2 = new InfoEvent(EventConstants.FINALIZE_REGENERATION, _patient.id, _patient);
                } else {
                    if (state == WorldConstants.CLEAN){
                        dispatch(new InfoEvent(EventConstants.CREATE_POPUP, GameConstants.NEXT_ELDER_POPUP, {speaker:"YetiOldBubble"}));
                        return (null);
                    };
                    return (null);
                };
            };
            _actionsActive = false;
            return (new InfoEvent(EventConstants.DISPATCH_DELAYED_EVENTS, null, [_local2, _local3]));
        }
        public function createSymbolCollectionWindow():InfoEvent{
            var _local1:Object = {symbols:_patient.currentTreatment.symbols, patientId:_patient.id, speaker:(_patient.petDisease + "Bubble"), podest:(_patient.type + "YoungBubble")};
            return (new InfoEvent(EventConstants.CREATE_POPUP, GameConstants.FOUNTAIN_GEMS_POPUP, _local1));
        }
        private function putPatientIntoMachine(_arg1:Boolean):void{
            _patient.isVisible = !(_arg1);
            var _local2:String = (_arg1) ? EventConstants.HIDE_VIEW : EventConstants.SHOW_VIEW;
            var _local3:InfoEvent = new InfoEvent(_local2, _patient.id);
            dispatch(_local3);
        }
        private function showBubble(_arg1:String):void{
            showSpeechBubble(SpeechBubbleConstants.TYPE_ICON_BUBBLE, {icon:_arg1});
        }

    }
}//package net.wooga.pets.models.world.vos.actors.machines 
